<?php 

require_once __DIR__."/../bo/MemberBO.php";


/**
 * Class MemberServer
 * 会员模块接口类
 */
class MemberServer extends Server {

    private $json_data=array("code" => 200,"msg" => "success");


    //会员登录接口
    function login(){

        if(checkEmptyParameter("phone")) throw new Exception("phone is null");

        if(checkEmptyParameter("password")) throw new Exception("password is null");

        $phone=$_POST["phone"];

        $pwd=$_POST["password"];


        //通过手机号码、密码检查会员是否存在，如果存在返回会员信息
        $member=MemberBO::loginByPhoneAndPassword($phone,$pwd);

        if(empty($member)) throw new Exception("member is null");

        $this->json_data["member"]=$member;

        $this->showJsonData($this->json_data);

    }

    //会员注册接口
    function regist(){

        if(checkEmptyParameter("phone")) throw new Exception("phone is null");

        if(checkEmptyParameter("password")) throw new Exception("password is null");

        $phone=$_POST["phone"];

        $pwd=$_POST["password"];

        //用户通过手机号码、密码注册
        $member=MemberBO::registByPhoneAndPassword($phone,$pwd);

        $this->json_data["member"]=$member;

        $this->showJsonData($this->json_data);

    }

    //重置密码
    function restPassword(){

        if(checkEmptyParameter("phone")) throw new Exception("phone is null");

        if(checkEmptyParameter("password")) throw new Exception("password is null");

        $phone=$_POST["phone"];

        $pwd=$_POST["password"];

        MemberBO::resetPassword($phone,$pwd);

        $this->showJsonData($this->json_data);
    }










     
}


